Skip to content

Conversation

@llucax
Copy link
Contributor

@llucax llucax commented Sep 25, 2025

When using the DeprecatedMember class directly, mypy will struggle because it will think the actual type of the value is DeprecatedMember instead of the real underlying value.

To fix this we create a simple generic wrapper deprecated_member() that will cast the DeprecatedMember to the type of the value.

@llucax llucax requested a review from a team as a code owner September 25, 2025 14:36
@llucax llucax requested review from Marenz and Copilot and removed request for Copilot September 25, 2025 14:36
@github-actions github-actions bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:enum Affects the enum module labels Sep 25, 2025
Copilot AI review requested due to automatic review settings September 25, 2025 14:36
@llucax llucax added this to the v1.3.0 milestone Sep 25, 2025
@llucax llucax added the type:enhancement New feature or enhancement visitble to users label Sep 25, 2025
@llucax llucax self-assigned this Sep 25, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new deprecated_member() function to improve typing when creating deprecated enum members. The function provides a type-safe wrapper around the existing DeprecatedMember class.

  • Adds a generic deprecated_member() function that returns the correct type for mypy
  • Updates all existing usage of DeprecatedMember to use the new function
  • Updates documentation and examples to reflect the new preferred approach

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/frequenz/core/enum.py Adds the new deprecated_member() function and updates documentation
tests/test_enum.py Updates tests to use new function and adds comprehensive test coverage
README.md Updates example to demonstrate the new function usage
RELEASE_NOTES.md Documents the new feature and upgrade guidance

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@llucax llucax enabled auto-merge September 25, 2025 14:36
@llucax llucax force-pushed the deprecated-type-fix branch from 1d48054 to 5345a23 Compare September 25, 2025 14:38
"""
return cast(ValueT, DeprecatedMember(value, message))


Copy link
Contributor

@Marenz Marenz Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So will you deprecate direct usage of DeprecatedMember then? 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it. But I think it is too meta 😆

But when we go for 2.0.0 I think I would make it private, we really don't need to expose it at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh, so nice to have gotten issue number 100 for:

Copy link

@daniel-zullo-frequenz daniel-zullo-frequenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a comment to check for. And LGTM

When using the `DeprecatedMember` class directly, `mypy` will struggle
because it will think the actual type of the value is `DeprecatedMember`
instead of the real underlying value.

To fix this we create a simple generic wrapper that will cast the
`DeprecatedMember` to the type of the value.

Signed-off-by: Leandro Lucarella <[email protected]>
Signed-off-by: Leandro Lucarella <[email protected]>
@llucax llucax force-pushed the deprecated-type-fix branch from 5345a23 to 9830fad Compare September 26, 2025 13:06
@llucax
Copy link
Contributor Author

llucax commented Sep 26, 2025

Updated.

@llucax llucax added this pull request to the merge queue Sep 26, 2025
Merged via the queue into frequenz-floss:v1.x.x with commit 3bc144e Sep 26, 2025
5 checks passed
@llucax llucax deleted the deprecated-type-fix branch September 26, 2025 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:docs Affects the documentation part:enum Affects the enum module part:tests Affects the unit, integration and performance (benchmarks) tests type:enhancement New feature or enhancement visitble to users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants